package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.Member;
import cn.wolfcode.crm.mapper.MemberMapper;
import cn.wolfcode.crm.query.MemberQueryObject;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.IMemberService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class MemberServiceImpl implements IMemberService {

    @Autowired
    private MemberMapper mapper;


    //新增会员
    public void save(Member entity) {
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        entity.setInput(employee);
        entity.setInputDate(new Date());
        entity.setState(0);
        mapper.insert(entity);
    }

    public void update(Member entity) {
        mapper.update(entity);
    }

    public void updateState(Member entity) {
        mapper.updateState(entity);
    }

    public void updateGroup(Member entity) {
        mapper.updateGroup(entity);
    }

    public void updateLabel(Member entity) {
        mapper.updateLabel(entity);
    }

    public List<Member> querymemberlist() {
        return mapper.querymemberlist();
    }

    public PageResult queryPage(MemberQueryObject qo) {
        PageResult pr = new PageResult();
        int total = mapper.queryForCount(qo);
        if (total == 0) {
            return pr;
        }
        List<Member> rows = mapper.queryForList(qo);
        pr.setTotal(total);
        pr.setRows(rows);
        return pr;
    }

    public void updateIntegral(Long id, Long number) {

        mapper.updateIntegral(id, new BigDecimal(number));
    }

    public Member get(Long id) {
        return mapper.get(id);
    }

    public void memberBalanceUpdate(Long id, BigDecimal salePrice) {
        mapper.memberBalanceUpdate(id,salePrice);
    }

}
